package ${pkgName};


import app.support.query.PageResult;
import com.farben.base.dto.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 企业
 *
 * @author leijmdas
 */
@RequestMapping("/${className}")
@Controller
public class  ${className}Controller {

    @Autowired
    private  ${className}Service service;

    @PostMapping("query")
    public @ResponseBody
    PageResult< ${className}> query(@RequestBody  ${className}.QueryParam qp) {
        if (qp.getParam() == null) {
            qp.setParam(new Event());
        }
        PageResult< ${className}> result = new PageResult< ${className}>();
        result.setData(service.findByQueryParam(qp));
        result.setTotal(service.countByQueryParam(qp));
        return result;
    }

    @PostMapping("count")
    public @ResponseBody
    JsonResult<Long> count(@RequestBody Event.QueryParam qp) {
        if (qp.getParam() == null) {
            qp.setParam(new  ${className}());
        }

        return JsonResult.success(service.countByQueryParam(qp));

    }

    /**
     * 保存
     *
     * @param entity
     * @return
     */
    @PostMapping("save")
    public @ResponseBody JsonResult<Long> save(@RequestBody  ${className} entity) {
        if (entity.getId() == null) {
            service.save(entity);
            return JsonResult.success(entity.getId());
        }
        service.update(entity);
        // service.updateNotNullPropsById(entity);
        return JsonResult.success(entity.getId());
    }
    @PostMapping("updateNotNull")
    public @ResponseBody JsonResult<Long>  updateNotNull(@RequestBody  ${className} entity) {

        service.updateNotNullPropsById(entity);
        return JsonResult.success(entity.getId());

    }

    //updateNotNullPropsById

    @GetMapping("deleteById/{id}")
    public @ResponseBody
    JsonResult deleteById(@PathVariable("id") Long id) {
        this.service.deleteById(id);
        return JsonResult.success();
    }

    @GetMapping("findById/{id}")
    public @ResponseBody
    JsonResult< ${className}>  findById(@PathVariable("id") Long id) {
        return JsonResult.success(this.service.findById(id));

    }


}
